/**
 * FileName: CheckInMapper
 * Author:   mjh
 * Date:     2019/8/1 12:09
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * mjh         修改时间           版本号              描述
 */
package com.woniuxy.main.mapper;

import com.woniuxy.main.pojo.CheckIn;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 〈一句话功能简述〉<br> 
 * 〈入住人员查询接口〉
 *
 * @author mjh
 * @create 2019/8/1
 * @since 1.0.0
 */
@Repository
public interface CheckInMapper {

    //查询全部
    @Select("select * from checkin where flag=0")
    List<CheckIn> findAll();

    //条件筛选查询，根据性别，房间号,入住日期筛选
    @Select("<script>"+"select * from checkin "+
            "<where>"+
            "<if test='room_id!=0'>"+
            "and room_id=#{room_id} "+
            "</if>"+
            "<if test='csex!=null'>"+
            "and csex=#{csex} "+
            "</if>"+
            "<if test='checkintime!=null'>"+
            "and checkintime=#{checkintime} "+
            "</if>"+
            "</where>" +
            "and flag=0"+
            "</script>")
    List<CheckIn> findByOther(CheckIn checkIn);


    //模糊查询，根据姓名，身份证，或者电话模糊查询
    @Select("<script>"+"select * from checkin where flag=0" +
            "<choose>" +
            "<when test='cname!=null'>" +
            "and cname like #{cname}" +
            "</when>" +
            "<when test='scard!=null'>" +
            "and scard like #{scard}" +
            "</when>" +
            "<when test='cphone!=null'>" +
            "and cphone like #{cphone}" +
            "</when>" +
            "</choose>"+
            "</script>")
    List<CheckIn> findByLike(CheckIn checkIn);


    /**
     * 新增:入住人对象
     * cname char(16) NULL
     * csex char(1) NULL
     * scard char(64) NOT NULL
     * cphone char(11) NULL
     * room_id int(11) NULL
     *
     * @param checkIn 入住人对象
     * @throws Exception 全部
     * @return 是否成功
     */
    @Insert("insert into `checkin`(cname,csex,scard,cphone,room_id,checkintime)" +
            " values(#{cname},#{csex},#{scard},#{cphone},#{room_id},#{checkintime})")
    boolean addCheckIn(CheckIn checkIn) throws Exception;

    @Select("/select * from room_id=#{roomid} and flag=0")
    List<CheckIn> findByRoomid(Integer roomid);
}